package com.smartkey.receiver;

import com.smartkey.constant.Constant;
import com.smartkey.sharedpreferences.SharePreferencesUtil;
import com.smartkey.utils.AppUtil;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;

public class KeyEventReceiver extends BroadcastReceiver {

	@Override
	public void onReceive(Context context, Intent intent) {
		SharePreferencesUtil util = new SharePreferencesUtil(context);
		int msg = intent.getIntExtra("msg", 0);
		boolean isDefault = false;
		String packageName = null;
		switch (msg) {
		case Constant.SINGLGE_CLICK:
			isDefault = util.isDefaultSingle();
			packageName = util.getSingleClickValue();
			break;
		case Constant.DOUBLE_CLICK:
			isDefault = util.isDefaultDouble();
			packageName = util.getDoubleClickValue();
			break;
		case Constant.TRIFECTA:
			isDefault = util.isDefaulTrifecta();
			packageName = util.getTrifectaClickValue();
			break;
		default:
			break;
		}
		System.out.println("########## packageName="+packageName);
		AppUtil.launchAppByPackageName(context, packageName, isDefault);

	}

}
